package com.longjianghuasheng.logistics.business.freight

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.RegexUtils
import com.longjianghuasheng.logistics.base.BaseMultiStateViewModel
import com.longjianghuasheng.logistics.data.model.bean.ApiResponseNoData
import com.longjianghuasheng.logistics.ext.checkPhone
import com.longjianghuasheng.logistics.ext.commit2
import com.longjianghuasheng.logistics.ext.judge
import com.longjianghuasheng.logistics.ext.toastNormal
import com.longjianghuasheng.logistics.repository.request.HttpRequestCoroutine

/**
 * @author：T
 * @date：2022/1/24:16:11
 * @des：
 */
class PersonalCooperationViewModel : BaseMultiStateViewModel() {
    var names: String = ""
    var sex: Int = 0
    var mobile: String = ""
    var card_no: String = ""
    var card_front: String = ""
    var card_back: String = ""

    val notify by lazy {

        MutableLiveData<ApiResponseNoData>()
    }


    fun people_work() {

        var isSuccess = false
        when {
            names.judge("请输入姓名") -> {}
            sex == 0 -> toastNormal("请选择性别")
            !checkPhone(mobile) -> {}
            card_no.judge("请输入身份证号") -> {}
            !RegexUtils.isIDCard18(card_no) -> toastNormal("身份证号有误")
            card_front.judge("请上传身份证正面") -> {}
            card_back.judge("请上传身份证背面") -> {}

            else -> isSuccess = true
        }

        if (!isSuccess) return




        commit2({
            HttpRequestCoroutine.people_work(
                names,
                sex,
                mobile,
                card_no,
                card_front,
                card_back
            )
        }, notify)
    }
}